home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Loadstar 10
/
010.d81
/
dos #24
< prev
next >
Wrap
Text File
|
2022-08-26
|
3KB
|
173 lines
DOS & Don'ts -- Part 24
by Jimmy Weiler
Last month we discussed the OPENing
and CLOSEing of a RELative file. This
month we will leap right into WRITING
and READING.
As with any other type of file, you
write to a RELative file with a PRINT#
statement. RELative files are unique
in that you must tell DOS which
record, and where in the record you
want to write.
You pass that information to DOS
via channel 15, the Command/Error
channel. All DOS commands and error
messages pass through channel 15.
To write to a REL file, we have to use
two commands -- a POSITION command
followed by a PRINT# statement.
POSITION command tells DOS what
record to write and where in the
record to start writing. The syntax
for the POSITION command is this:
PRINT#15,"P"CHR$(<channel number>)
CHR$(<lo record byte>)
CHR$(<hi record byte>)
CHR$(<byte in record>)
Don't be intimidated by all that
gibberish. It's not hard at all once
you see a few examples.
File records start with record 1.
In each record, the bytes start with
number 1. So, to write our PHONEFILE's
first record we do this:
1000 PRINT#15,"P"CHR$(4)CHR$(1)CHR$(0)
CHR$(1)
2000 PRINT#3,"SCHLABOTNIK"
3000 PRINT#15,"P"CHR$(4)CHR$(1)CHR$(0)
CHR$(13)
4000 PRINT#3,"8687247"
Now let's tear that apart until we
understand it.
We PRINT#15 because POSITION is a
DOS command, and must be sent through
the Command/Error channel. The "P",
of course, stands for POSITION.
CHR$(4) tells DOS we want to use
disk channel 4. You remember from
last month when we discussed OPEN,
that we opened our file as file 3,
unit 8, channel 4, "PHONEFILE".
CHR$(1)CHR$(0) is the record number,
which must always be represented by
two characters.
Here's how you can calculate the
values you must use to access any
record number.
10 INPUT"Record number";R
20 HB=INT(R/256)
30 LB=R-(HB*256)
Then use LB and HB as the characters
for your record number:
40 PRINT#15,"P"CHR$(4)CHR$(LB)CHR$(HB)
CHR$(1)
The last parameter of our POSITION
command, CHR$(1) is used to point the
I/O to the first character of the
record. You can use values ranging
from 1 to your record length for this
parameter. Your PRINT# will begin
at whatever character in your record
this BYTE pointer points to.
Don't omit this BYTE parameter. If
it is left off you will access the
13th character in the record instead
of the first. (That's because the
carriage return after the POSITION
command would be used as the BYTE
parameter.)
Once you have POSITIONED, the PRINT#
statement that follows writes into the
record sequentially from the character
pointed to by the BYTE parameter. You
MUST POSITION every time you PRINT#
into a relative file.
------- continued in Part 25 ---------